import { defineStore } from 'pinia';
import service from '/@/utils/request';
import { query } from '/@/utils/params';
import { Account } from '/@/views/system/account/account';
import { easyDate } from '/@/utils/formatTime';

export interface OrderRecordVo {
	id?: string;
	name: string; // 公司名称
	tel: string; // 公司电话
	contactName: string; // 联系人
	contactTel: string; // 联系电话
	address: string; // 地址
	account?: string; // 账号
	password?: string; // 密码
}

export interface OrderRecordDTO {
	name: string; // 公司名称
	tel: string; // 公司电话
	contactName: string; // 联系人
	contactTel: string; // 联系电话
	address: string; // 地址
	account: Account; // 账号
	password: string; // 密码
	createdAt: string;
}
export const useOrderRecord = defineStore('orderRecord', {
	actions: {
		async getOrderRecordList(name: string, pageSize: number, pageNumber: number) {
			return service.get(query('/api/orderrecord', { name, pageSize, pageNumber })).then((res) => {
				res.list = res.list.map((c: OrderRecordDTO) => {
					return {
						...c,
						account: c.account.account,
						createdAt: easyDate(c.createdAt),
					};
				});
				return res;
			});
		},
		/**
		 * 新增
		 * @param vo
		 * @returns
		 */
		async saveOrderRecord(vo: OrderRecordVo) {
			return service.post('/api/orderrecord/create', vo);
		},

		/**
		 * 编辑
		 */
		async updateOrderRecord(vo: OrderRecordVo) {
			return service.patch(`/api/orderrecord/${vo.id}`, vo);
		},

		async delete(id: string) {
			return service.delete(`/api/orderrecord/${id}`);
		},
		async toggoleStatus(id: string, status: number) {
			return service.patch(`/api/orderrecord/${id}/status?status=${status}`);
		},
	},
});
